using SmartLink.Domain.Entity;
using SmartLink.IRepository;
using SmartLink.Repository.Base;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Common;
using DapperExtensions;
using Dapper;

namespace SmartLink.Repository
{
    public class SYS_AttachmentRepo : RepositoryBase<SYS_Attachment>, ISYS_AttachmentRepo
    {
        public void Add(IEnumerable<SYS_Attachment> entities, DbTransaction tran)
        {//报错
            tran.Connection.Insert<SYS_Attachment>(entities, tran);
        }

        public IEnumerable<SYS_Attachment> GetByForeignKey(string tableName, int id)
        {
            var sql = "SELECT * FROM SYS_Attachment a WHERE a.FK_TableName=@TableName AND a.FK_EntryId=@EntryId";
            var param = new { TableName = tableName, EntryId = id };
            using (var conn = CreateConn())
            {
                return conn.Query<SYS_Attachment>(sql, param);
            }
        }
    }
}
